package com.zzxx.service.impl;

import com.github.pagehelper.PageHelper;
import com.zzxx.domain.Permission;
import com.zzxx.domain.Role;
import com.zzxx.mapper.PermissionMapper;
import com.zzxx.mapper.RoleMapper;
import com.zzxx.service.RoleService;
import com.zzxx.utils.UUIDUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class RoleServiceImpl implements RoleService {
    @Autowired
    private RoleMapper roleMapper;
    @Autowired
    private PermissionMapper permissionMapper;
    @Override
    public List<Role> queryAll(int pageNum, int pageSize) {
        PageHelper.startPage(pageNum, pageSize);
        return roleMapper.findAll();
    }

    @Override
    public void insertRole(Role role) {
        role.setId(UUIDUtils.uuid());
        roleMapper.add(role);
    }

    @Override
    public List<Permission> findOtherPermissionsById(String id) {
        return permissionMapper.findOtherPermissionsById(id);
    }

    @Override
    public void addPermission(String[] ids, String roleId) {
        for (String permissionId : ids){
            permissionMapper.addPermission(permissionId, roleId);
        }
    }
}
